package com.qianfeng.yime;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import com.qianfeng.yime.adapter.CommonFragmentAdapter;
import com.qianfeng.yime.fragment.TutorialImageFragment;
import com.qianfeng.yime.fragment.TutorialJumpFragment;

import java.util.LinkedList;

/**
 * Created by IDEA
 * User : SL
 * on  2015/3/9.
 * 20:59
 */
public class TutorialActivity extends FragmentActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tutorial);

        //设置显示过欢迎界面，下次直接进入主界面
        SharedPreferences sp = getSharedPreferences(Constants.SP_APP_DATA, MODE_PRIVATE);
        SharedPreferences.Editor edit = sp.edit();
        edit.putBoolean(Constants.SP_KEY_TUTORIAL_SHOWN, true);
        edit.commit();

        ViewPager viewPager = (ViewPager) findViewById(R.id.pager_tutorial);

        LinkedList<Fragment> fragments = new LinkedList<Fragment>();
        //TODO 添加教程界面

        TutorialImageFragment imageFragment = new TutorialImageFragment();
        Bundle args = new Bundle();
        args.putInt(Constants.ARG_TUTORIAL_IMAGE_LAYOUT_ID, R.layout.fragment_tutorial_image1);
        imageFragment.setArguments(args);
        fragments.add(imageFragment);

        imageFragment = new TutorialImageFragment();
        args = new Bundle();
        args.putInt(Constants.ARG_TUTORIAL_IMAGE_LAYOUT_ID, R.layout.fragment_tutorial_image2);
        imageFragment.setArguments(args);
        fragments.add(imageFragment);

        fragments.add(new TutorialJumpFragment());

        CommonFragmentAdapter adapter = new CommonFragmentAdapter(
                getSupportFragmentManager(),
                fragments
        );

        viewPager.setAdapter(adapter);

    }
}